/*   
 * Copyright 2011-2012 the original author or authors.   
 *   
 * Licensed under the Apache License, Version 2.0 (the "License");   
 * you may not use this file except in compliance with the License.   
 * You may obtain a copy of the License at   
 *   
 *      http://www.apache.org/licenses/LICENSE-2.0   
 *   
 * Unless required by applicable law or agreed to in writing, software   
 * distributed under the License is distributed on an "AS IS" BASIS,   
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   
 * See the License for the specific language governing permissions and   
 * limitations under the License.   
 */
package code.google.com.p.antigovframe.sample

import groovy.util.GroovyTestCase;

import javax.persistence.*


import org.hibernate.cfg.*
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.SessionFactory;
import org.hibernate.Session;

/**
 * @author Jacob Lee
 * @since 2012. 8. 10.
 * 
 */
class BaseDAOTest<T> extends GroovyTestCase {
	
	def realSession
	def factory
	
	def hibProps = [
		"hibernate.dialect": "org.hibernate.dialect.HSQLDialect",
		"hibernate.connection.driver_class": "org.hsqldb.jdbcDriver",
		"hibernate.connection.url": "jdbc:hsqldb:mem:testdb",
		"hibernate.connection.username": "sa",
		"hibernate.connection.password": "",
		"hibernate.connection.pool_size": "1",
		"hibernate.connection.autocommit": "true",
		"hibernate.cache.provider_class": "org.hibernate.cache.NoCacheProvider",
		"hibernate.hbm2ddl.auto": "create-drop",
		"hibernate.show_sql": "true",
		"hibernate.transaction.factory_class": "org.hibernate.transaction.JDBCTransactionFactory",
		"hibernate.current_session_context_class": "thread"
	]
	
	def configureHibernate(props) {
		def config = new AnnotationConfiguration()
		props.each { k, v -> config.setProperty(k, v) }
		config.addAnnotatedClass(Task)
		return config
	}
 
	void setRealSession () {
		factory = configureHibernate(hibProps).buildSessionFactory()
		realSession = factory.currentSession
		 
		assertNotNull realSession
	}
	
}
